﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using common.pages;
using Com.queryzer2.Domain.Entities;
using common;

namespace Com.AlbLab.CR.Web.pages
{
    public partial class Pratica : BasePage
    {
        GEP_TESTATA entity = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            //la prima fase deve essere inserita con codice 10-->prima fase 
            //insert into gep_fase (fas_cod_pratica, fas_cod_servizio,fas_nro_fase, fas_progr_fase, fas_unit_oper,fas_dt_arrivo,fas_stato,fas_id)values
            //         (1,'D01',10,1,1,sysdate,1,ASM_GEP_FASE_ID.nextval);
            if (!Page.IsPostBack)
            {
                decimal prt = 1;
                if (common.TempSession.getBag() != null && common.TempSession.getBag().tipo == "CODICE_PRATICA")
                {
                    prt = Convert.ToDecimal(common.TempSession.getBag().valore);
                }
                entity = BasePage.Services.GestioneInserimentoService.loadPratica_ByCode(prt, true);
                common.SessionManager<GEP_TESTATA>.set(SessionKeys.CURRENT_TESTATA, entity);

                PraticaViewerSmall1.entity = entity;
                PraticaViewerSmall1.Pratica_id = entity.Id_tes_cod_pratica.ToString();
                Grid1.NumColonne = 6;
                Grid1.H0 = "";
                Grid1.H1 = "Fase";
                Grid1.H2 = "Ufficio";
                Grid1.H3 = "Data Inizio";
                Grid1.H4 = "Data Fine";
                Grid1.Visible = true;
                Grid1.DataSource = common.ToGenericListTransformers.transform(entity.Gep_fase);

                
                switch (entity.Gep_ana_serv.Id_ser_cod_servizio)
                {
                    case "VT0":
                    case "SB0":
                    case "SW0":
                    case "SW1":
                         zNST_VT0_SB0_SW0_SW11.setdRecord(entity.Gep_risposta.Response);
                         zNST_VT0_SB0_SW0_SW11.Visible = true;
                        break;
                    case "SM0":
                    case" SG0":
                    case "CA0":
                    case "RF0":
                        zNST_SM0_SG0_CA0_RF01.setdRecord(entity.Gep_risposta.Response);
                        zNST_SM0_SG0_CA0_RF01.Visible = true;
                        break;
                    case "PR0":
                        zNST_PR01.setdRecord(entity.Gep_risposta.Response);
                        zNST_PR01.Visible = true;
                        break;
                    case "EL1":
                    case "VA0":
                    case "SG1":
                    case "SI0":
                    case "RE0":
                    case "RE1":
                        zNST_EL1_VA0_SG1_SI0_RE0_RE11.setdRecord(entity.Gep_risposta.Response);
                        zNST_EL1_VA0_SG1_SI0_RE0_RE11.Visible = true;
                        break;
                    case "EL0":
                    case "AP0":
                    case "VP0":
                    case "CF0":
                    case "CT0":
                        zNST_EL0_AP0_VP0_CF0_CT01.setdRecord(entity.Gep_risposta.Response);
                        zNST_EL0_AP0_VP0_CF0_CT01.Visible = true;
                        break;
                }
                
            }
            
           
        }

        protected void Grid1_OnSelect(string commandName, GenericListDTO row)
        { 
            Grid1.Clear();
            common.TempSession.setBag("CODICE_FASE", row.Id.Split('/')[0]);
            Response.Redirect("Fase.aspx");
        }

        protected void Response_onSave(object sender , GEP_RISPOSTA e, bool init)
        {
          
           if (init ==false)
                BasePage.Services.PraticaBaseService.UpdateResponse(e);
            else
                BasePage.Services.PraticaBaseService.InsertResponse(e);
            common.SessionManager<GEP_TESTATA>.get(SessionKeys.CURRENT_TESTATA).Gep_risposta=e;
        }
    }
}
